﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Incubator
{
    public partial class WebUserControl1 : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null || (int)Session["UserID"] == -1)
                Response.Redirect("main.aspx");

            webRef.User u = (webRef.User)Session["User"];
            webRef.Company c = Global.incuServ.GetCompany(u.company_id);

            lblUserName.Text = u.username;
            lblCompanyName.Text = c.name;
            lblMoney.Text = c.money.ToString();

            webRef.Share[] shares = Global.incuServ.GetAllUserShares(u);
            //show them in the table

            foreach (webRef.Share s in shares)
            {
                TableCell tc1 = new TableCell();
                TableCell tc2 = new TableCell();
                TableCell tc3 = new TableCell();
                TableRow tr = new TableRow();

                

                tc1.Controls.Add(new LiteralControl(s.company.name));
                tc2.Controls.Add(new LiteralControl(s.quantity.ToString()+"%"));
                tc3.Controls.Add(new LiteralControl(s.isOnMarket ? "On Market" : "Not On Market"));
                

                tr.Cells.Add(tc1);
                tr.Cells.Add(tc2);
                tr.Cells.Add(tc3);
                tblCompanyShares.Rows.Add(tr);
            }
        }
    }
}